
// 验证手机号
export function isPhone (value) {
  var regu = /(^[1][3][0-9]{9}$)|(^[1][5][0-9]{9}$)|(^[1][6][0-9]{9}$)|(^[1][8][0-9]{9}$)|(^[1][9][0-9]{9}$)|(^[1][4][0-9]{9}$)|(^[1][7][0-9]{9}$)/
  if (regu.test(value)) {
    return true
  } else {
    return false
  }
};

export function isEmail (value) {
  var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/
  // var regu = /(^[1][3][0-9]{9}$)|(^[1][5][0-9]{9}$)|(^[1][6][0-9]{9}$)|(^[1][8][0-9]{9}$)|(^[1][9][0-9]{9}$)|(^[1][4][0-9]{9}$)|(^[1][7][0-9]{9}$)/
  if (myreg.test(value)) {
    return true
  } else {
    return false
  }
};



// 获取参数
export function getParams () {
  return JSON.parse(localStorage.getItem('saveInfor')).agentId
};

// 判断设备类型

export function equipment () {
  let type
  var u = navigator.userAgent
  var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1 // android安卓
  var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/) // ios苹果
  if (isAndroid) {
    type = 'android'
  }
  if (isiOS) {
    type = 'ios'
  }
  return type
};

function isEmpty (target) {
  if (target == null || target == '' || target == 'undefined' || target == undefined) {
    return false
  }
  return true
}

/** 判断输入的15位或者18位身份证号码是否正确**/
export function parseId (pId) {
  var arrVerifyCode = [1, 0, 'x', 9, 8, 7, 6, 5, 4, 3, 2]
  var wi = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
  if (pId.length != 15 && pId.length != 18) { return true }
  var ai = (pId.length == 18) ? pId.substr(0, 17) : pId.substr(0, 6) + '19' + pId.substr(6)
  if (!/^\d+$/.test(ai)) { return true }
  var yyyy = ai.substr(6, 4)
  var mm = ai.substr(10, 2) - 1
  var dd = ai.substr(12, 2)
  var d = new Date(yyyy, mm, dd)
  var year = d.getFullYear()
  var mon = d.getMonth()
  var day = d.getDate()
  var now = new Date()
  if (year != yyyy || mon != mm || day != dd || d > now || now.getFullYear() - year > 140) { return true }
  for (var i = 0, ret = 0; i < 17; i++) ret += ai.charAt(i) * wi[i]
  ai += arrVerifyCode[ret %= 11]
  if (pId.length == 18 && pId.toLowerCase() != ai) { return true }

  return false
}

export function ChangeBg (color) {
  document.body.style.backgroundColor = color
}


export function debounce(func,delay){
  var timer = null;
  return function() {
      var context = this;
      var args = arguments;
      if (timer) {
          clearTimeout(timer)
      }
      timer = setTimeout(function() {
          func.apply(context, args);
          timer = null;
      }, delay);
  }
}

